package components.scenes;

import java.awt.Color;
import java.awt.Font;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Label;
import com.uqbar.vainilla.appearances.Rectangle;
import com.uqbar.vainilla.events.constants.Key;
import components.decoration.Background;

public abstract class ScoreableEndScene extends GameScene {

	private int score;
	
	public ScoreableEndScene (int aScore, int width, int height){
		this.score = aScore;
		this.addBackground(width, height);
		this.addGameOverText();
		this.addScore(score);
		this.addRestart();
	}



	private void addScore(int score) {

		Label scoreLabel = new Label(new Font(Font.MONOSPACED, Font.BOLD, 46), Color.WHITE, "Your score: " + score);
		GameComponent scoreGc = new GameComponent();
		scoreGc.setAppearance(scoreLabel);
		scoreGc.setX(300);
		scoreGc.setY(400);
		this.addComponent(scoreGc);
	}

	private void addRestart() {

		Label restart = new Label(new Font(Font.SERIF, Font.PLAIN, 20), Color.RED, "Press enter to play again");
		GameComponent gcRestart = new GameComponent(){
			public void update(DeltaState delta){
				super.update(delta);
				if (delta.isKeyPressed(Key.ENTER)){
					this.getGame().setCurrentScene(getRestartScene());
				}
			}

		};
		gcRestart.setAppearance(restart);
		gcRestart.setX(350);
		gcRestart.setY(500);
		this.addComponent(gcRestart);
	}

	private void addGameOverText() {
		Label gameOver = new Label(new Font(Font.SERIF, Font.PLAIN, 46), Color.WHITE, "GAME OVER");
		Label smile = new Label(new Font(Font.SERIF, Font.PLAIN, 50), Color.WHITE, "=(");
		
		GameComponent gcGoText, gcSmile;
		
		
		gcGoText = new GameComponent();
		gcGoText.setAppearance(gameOver);
		gcGoText.setX(300);
		gcGoText.setY(200);
		
		gcSmile = new GameComponent();
		gcSmile.setAppearance(smile);
		gcSmile.setX(gcGoText.getX() + 50);
		gcSmile.setY(gcGoText.getY() + 80);
		
		this.addComponent(gcSmile);
		this.addComponent(gcGoText);

	
	}
	private void addBackground(int width, int height) {
		this.addComponent(new Background(new Rectangle(Color.BLACK, width, height)));
	}

	public abstract GameScene getRestartScene();
	public int getScore() {
		return score;
	}

	public void setScore(int score) {
		this.score = score;
	}
}
